package com.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.mapper.Wms_Ware_Info_Mapper;
import com.shop.mapper.Wms_Ware_Sku_Mapper;
import com.shop.pojo.wms.Wms_Ware_Info;
import com.shop.pojo.wms.Wms_Ware_Sku;
import com.shop.service.Wms_Ware_Sku_Service;
import com.shop.utils.LayuiUtils;
import com.shop.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商品库存-李贝贝
 */
@Service
public class Wms_Ware_Sku_ServiceImpl implements Wms_Ware_Sku_Service {

    @Autowired
    private Wms_Ware_Sku_Mapper wms_ware_sku_mapper;

    @Autowired
    private Wms_Ware_Info_Mapper wms_ware_info_mapper;

    /**
     * 多条件显示所有商品库存
     * @param pages
     * @param wms_ware_sku
     * @return
     */
    @Override
    public LayuiUtils<Wms_Ware_Sku> find_Wms_Ware_Sku(Page<Wms_Ware_Sku> pages, Wms_Ware_Sku wms_ware_sku) {
        LayuiUtils<Wms_Ware_Sku> layuis = new LayuiUtils<>();
        QueryWrapper<Wms_Ware_Sku> query = new QueryWrapper<>();

        if(wms_ware_sku.getWare_id() != null){
            query.eq("ware_id",wms_ware_sku.getWare_id());
        }
        if(wms_ware_sku.getSku_id() != null){
            query.eq("sku_id",wms_ware_sku.getSku_id());
        }
        Page<Wms_Ware_Sku> wms_ware_skuPage = wms_ware_sku_mapper.selectPage(pages,query);
        layuis.setCount(wms_ware_skuPage.getTotal());
        layuis.setData(wms_ware_skuPage.getRecords());
        return layuis;
    }

    /**
     * 添加
     * @param wms_ware_sku
     * @return
     */
    @Override
    public R insert_ware_sku(Wms_Ware_Sku wms_ware_sku) {
        int insert = wms_ware_sku_mapper.insert(wms_ware_sku);
        if (insert > 0){
            return R.success();
        }
        return R.error(500,"添加失败");
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @Override
    public R delete_ware_sku(List<Long> id) {
        int ids = wms_ware_sku_mapper.deleteBatchIds(id);
        if (ids > 0){
            return R.success();
        }else {
            return R.error(500,"删除失败");
        }
    }

    /**
     * 修改
     * @param wms_ware_sku
     * @return
     */
    @Override
    public R update_ware_sku(Wms_Ware_Sku wms_ware_sku) {
        int o = wms_ware_sku_mapper.updateById(wms_ware_sku);
        if (o > 0){
            return R.success();
        }else {
            return R.error(500,"修改失败");
        }
    }

    /**
     * 后台查询下拉框所有的仓库显示页面
     * @return
     */
    @Override
    public List<Wms_Ware_Info> find_admin_ware_info_All() {
        List<Wms_Ware_Info> wms_ware_infos = wms_ware_info_mapper.selectList(new QueryWrapper<>());
        return wms_ware_infos;
    }
}
